<template>

  <a-modal
    title="添加重点件"
    :width="1400"
    :visible="visible"
    @ok="ok()"
    @cancel="cancel()"
  >
    <div>
      <a-form layout="inline" style="margin-bottom: 10px">
        <a-row :gutter="24" type="flex">
          <a-col :md="16" :sm="24">
            <a-checkbox v-model:checked="data.djdw">是否选择省级以上单位</a-checkbox>
            <a-checkbox v-model:checked="data.scxfbz">初重件标志</a-checkbox>
            <a-checkbox v-model:checked="checked1">是否越级</a-checkbox>
            <a-checkbox v-model:checked="checked3">是否联名信</a-checkbox>
            <a-checkbox v-model:checked="checked4">是否集体访</a-checkbox>
            <a-checkbox v-model:checked="data.yybz">扬言标志</a-checkbox>
            <a-checkbox v-model:checked="data.sfssbz">是否涉法涉诉</a-checkbox>
            <a-checkbox v-model:checked="data.jabz">是否积案</a-checkbox>
            <a-checkbox v-model:checked="data.sksflbz">三跨三分类</a-checkbox>
            <a-checkbox v-model:checked="checked2">是否转督办</a-checkbox>
            <span style="margin-left:20px ">请选择信访来源:</span>
            <a-select placeholder="请选择订单状态" v-model="data.xfxs" :options="statusOptions" style="width: 200px;margin-left:10px"></a-select>
          </a-col>
          <a-col :md="6" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-spin :spinning='downLoading' tip=" 正在下载数据，请耐心等待">
    <a-table
      ref="table"
      rowKey="id"
      size="middle"
      :row-selection="rowSelection"
      :rowKey="record => record.xfjbh"
      :pagination="ipagination"
      @change="handleTableChange"
      bordered
      :columns="columns"
      :dataSource="dataSource">
      <span slot='scxfbz' slot-scope='text, record,index'>
          <span v-if="record.scxfbz==1">初件</span>
          <span v-else>重件</span>
      </span>
    </a-table>
    </a-spin>
    <AddZdj ref='addZdj' v-on:refreshXfj="refreshXfj"></AddZdj>
  </a-modal>
</template>

<script>
import EpaWeekly from '@/myService/EpaWeekly'
import AddZdj from '../../../../views/epa/epa-weekly/Modal/AddZdj'
export default {
  name: 'AddXfj',
  components:{
    AddZdj
  },
  data(){
    return{
      downLoading:true,
      statusOptions:[
        {
          label:'网上纠错', value:'0900'
        },
        {
          label:'网上咨询', value:'0304'
        },
        {
          label:'来信', value:'0100'
        },
        {
          label:'来访', value:'0200'
        },
        {
          label:'网上建议', value:'0303'
        },
        {
          label:'来电', value:'0400'
        },
        {
          label:'视频信访', value:'0500'
        },
        {
          label:'领导信箱', value:'0600'
        },
        {
          label:'人民建议征集', value:'0700'
        },
        {
          label:'其他', value:'0999'
        },
        {
          label:'短信信访', value:'0301'
        },
        {
          label:'国家监督', value:'9001'
        },
        {
          label:'网上举报', value:'0305'
        },
        {
          label:'全部', value:''
        },
      ],
      checked1: false,
      checked2: false,
      checked3: false,
      checked4: false,
      checked:[],
      ipagination:{
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      selectedRowKeys:[],
      selectedRows:[],
      data:{
        currentPage:1,
        djdw:false,
        pageSize: 10,
        scxfbz:false,
        yjbz:false,
        jtxfbz:false,
        yybz:false,
        sfssbz:false,
        jabz:false,
        sksflbz:false,
        xfxs:''
      },
      visible:false,
      dataSource:[{
        xfjbh:'',
        state:0
      }],
      confirmImportLoading:false,
      columns: [
        {
          title:'信访件编号',
          align:"center",
          dataIndex: 'xfjbh'
        },
        {
          title:'标题',
          align:"center",
          dataIndex: 'bt'
        },
        {
          title:'问题属地',
          align:"center",
          dataIndex: 'wtsd'
        },
        {
          title:'姓名',
          align:"center",
          width:80,
          dataIndex: 'xm'
        },
        {
          title:'概况',
          dataIndex: 'gk',
          ellipsis: true
        },
        // {
        //   title:'信访人诉求',
        //   dataIndex: 'xfrsq',
        //   ellipsis: true
        // },
        {
          title:'答复意见内容',
          dataIndex: 'clqk',
          ellipsis: true
        },
        {
          title:'内容分类',
          align:"center",
          width:100,
          dataIndex: 'nrfl'
        },
        {
          title: '初重件',
          key: 'scxfbz',
          width: 60,
          align: 'center',
          scopedSlots: { customRender: 'scxfbz' }
        },
        {
          title:'去向单位',
          align:"center",
          width:100,
          dataIndex: 'dwmc'
        },
        {
          title:'登记单位',
          align:"center",
          width: 100,
          dataIndex: 'djdw'
        },
      ],
      reportId:0,
    }
  },
  computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          console.log(selectedRowKeys);
          console.log(selectedRows)
          this.selectedRowKeys=selectedRowKeys
          this.selectedRows=selectedRows;
        },
        selectedRowKeys:this.selectedRowKeys,
        getCheckboxProps: record=>({
          props:{
            disabled:record.state==1
          }
        })

      };
    },
  },
  methods:{
    searchReset(){
      this.checked1=false;
      this.checked2=false;
    },
    searchQuery(){
      this.loading()
    },
    open(reportId,check){
      this.checked=check;
      this.reportId=reportId
      this.visible = true;
      this.loading();
    },
    ok(){
      this.$refs.addZdj.open(this.selectedRows,this.selectedRowKeys,this.reportId);
    },
    cancel(){
      this.$emit('Refresh')
      this.file=null;
      this.visible = false
    },
    async refreshXfj(selectedRowKeys) {
      if(selectedRowKeys.length>0){
        selectedRowKeys.forEach((item)=>{
          this.checked.push(item)
        })
      }
      console.log(1,this.checked)
      await this.loading()
      this.selectedRowKeys = []
      this.selectedRows = []

      this.$emit('Refresh')
    },
    async loading() {
      this.downLoading=true
      let date=sessionStorage.getItem('date');
      this.data.date=date
      console.log(this.data)
      if (this.checked1 == true || this.checked2 == true) {
        this.data.yjbz = true;
      } else {
        this.data.yjbz = false;
      }
      console.log(this.checked3)
      if (this.checked3 == true || this.checked4 == true) {
        console.log("1")
        this.data.jtxfbz = true;
      } else {
        console.log("2")
        this.data.jtxfbz = false;
      }

      await EpaWeekly.getXfj(this.data).then((res) => {
        if (res.code == 500) {
          this.$message.success("没有数据")
          this.dataSource = null;
        }
        console.log(res)
        this.dataSource = res.result.records;
        this.ipagination.current = res.result.current
        this.ipagination.total = res.result.total
        for (var i = 0; i < this.dataSource.length; i++) {
          for (var j = 0; j < this.checked.length; j++) {
            if (this.dataSource[i].xfjbh === this.checked[j]) {
              this.dataSource[i].state = 1;
            }
          }
        }
      }).finally(
        ()=>{
          this.downLoading=false
        }
      )
      console.log(2,this.dataSource)
      // console.log("zheci")
      // console.log(this.check)
      // console.log(this.dataSource)
    },
    handleTableChange(pagination){

      this.data.currentPage=pagination.current
      this.data.pageSize=pagination.pageSize

      this.loading()
    },
  }
}
</script>

<style scoped>

</style>